
*directory to be changed 
 cd "/Users/eliemurard/Dropbox/immigration welfare attitudes-Freeman/dofile_1718/replication JEG/"

	
	use "replication_data_JEG.dta", clear 


	global regional  ln_pop_nat_value ln_gdp_PPP_percap unemp2064 ln_N_skill_ratio
	
	
	
    global control   i.coh#i.male   i.male#i.edulvla   immi_eu immi_noeu parent_immi_eu parent_immi_noeu edu_parents_2 edu_parents_3 edu_parents_4  miss_eduparents ///
					     nb_child nb_adu nb_elder  domicil2 domicil3 domicil4 domicil5  ///
					   self_employed hswrk edctn uempla uempli dsbld rtrd  
					   
	global inc_control  i.isco88_2d i.quant_hhincome  i.hincfel		
	global subview_control     i.ipeqopt  i.iphlppl  i.lrscale i.pplfair 

	global option varlabels tex plain fragment bdec(3) se starloc(1) starlevels(10 5 1) nocenter  

	global model_1   "Country-year FE", "X" \ "Regional control", "" \ "Basic Indiv-controls", "" \ "Income controls", "" \ "Ideology controls", ""   
	global model_2	 "Country-year FE", "X"  \ "Regional control", "X" \ "Basic Indiv-controls", "" \ "Income controls", "" \ "Ideology controls", ""  
	global model_3	 "Country-year FE", "X"  \ "Regional control", "X" \ "Basic Indiv-controls", "X" \ "Income controls", "" \ "Ideology controls", ""     
	global model_4   "Country-year FE", "X"  \ "Regional control", "X" \ "Basic Indiv-controls", "X" \ "Income controls", "X" \ "Ideology controls", ""    
	global model_5	 "Country-year FE", "X"  \ "Regional control", "X" \ "Basic Indiv-controls", "X" \ "Income controls", "X" \ "Ideology controls", "X"    

	capt program drop breakpoint_2010_qua 
	program define breakpoint_2010_qua  
	global  breakpoint = -(_b[pct_2010] /(2* _b[pct_2010_sq]))
	global  breakpoint = round($breakpoint, 0.001) 
	end
	
	
******************************************************************************************************************************  	
****     Table 1 		
******************************************************************************************************************************  	
		
	 nois corr 	Z_redis_scale   Z_support_incequal     Z_gvslvol Z_gvslvue Z_gvcldcr Z_sbstrec   Z_sbbsntx Z_sblazy 
		
				
******************************************************************************************************************************  	
****     Table 2		
******************************************************************************************************************************  	
		
	
foreach y of varlist noimbro  {

	local l  :  variable label `y'
	dis "`l'"
	tempvar samplee
	g  `samplee' = ess_sample ==1 & sample_`y'==1 
	
	global m1 pct_lag  
	
	outreg, clear(table2) 
	
	qui  areg  `y'    $m1      if   `samplee'==1 ,     absorb(id_country_yearess) vce(cluster id_nuts2)
	outreg, merge(table2)  	 nod keep( $m1   ) ctitle("", "`l'")  ${option} addrows( "$model_1" ) 
	
	qui  areg `y'    $m1  $regional      if   `samplee'==1 ,    absorb(id_country_yearess)  vce(cluster id_nuts2)
	 outreg, merge(table2)     	 nod keep( $m1   )   ${option}  ctitle("", "") addrows( "$model_2"  ) 
	 
	qui  areg `y'   $m1  $regional $control     if   `samplee'==1 ,  absorb(id_country_yearess)  vce(cluster id_nuts2)
	outreg, merge(table2)   	 nod keep( $m1   )   ${option} ctitle("", "")  addrows( "$model_3"  ) 
	
	qui  areg `y'  $m1  $regional $control $inc_control    if   `samplee'==1 , absorb(id_country_yearess) vce(cluster id_nuts2)
	outreg, merge(table2)   	 nod keep( $m1  ) ${option} ctitle("", "")  addrows( "$model_4" ) 
	 
	qui  areg `y'  $m1   $regional $control $inc_control  $subview_control  if   `samplee'==1 , absorb(id_country_yearess)  vce(cluster id_nuts2)
	outreg, merge(table2)  	 nod keep( $m1  ) ctitle("", "")   ${option} addrows( "$model_5" ) 
	
	}	   
	*
	nois outreg , replace  replay(table2)  $option   title(Table 2)
  
  
******************************************************************************************************************************  	
****     Table 3		
******************************************************************************************************************************  	
	
	
	local y= "Z_pca_score"  
	
	local l  :  variable label `y'
	dis "`l'"
	tempvar  samplee 
	g  `samplee' = ess_sample ==1 & sample_`y'==1 
	qui su `y'    if   `samplee'==1  
	local av = round(r(mean),0.01) 
 
	local equa1 = "areg"
	local equa2 = "absorb( id_country_yearess )"	

	outreg, clear(table3)	
	
	global m1  pct_2010  pct_2010_sq 
	
	qui  `equa1' `y'    $m1      if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 breakpoint_2010_qua 
	 outreg, merge(table3) 	 nod keep( $m1   ) ctitle(" ", "`l'")  ${option} addrows( "$model_1" \ "breakpoint", $breakpoint ) 
	  
	qui  `equa1' `y'    $m1  $regional      if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 breakpoint_2010_qua
	 outreg, merge(table3)  	 nod keep( $m1   ) ctitle(" ", "")  ${option} addrows( "$model_2" \ "breakpoint", $breakpoint ) 
	  
	qui  `equa1' `y'    $m1  $regional $control     if   `samplee'==1 ,     `equa2' vce(cluster id_nuts2)
	 breakpoint_2010_qua
	 outreg, merge(table3)  	 nod keep( $m1   ) ctitle(" ", "")  ${option} addrows( "$model_3" \ "breakpoint", $breakpoint ) 
	  
	qui  `equa1' `y'  $m1  $regional $control $inc_control    if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 breakpoint_2010_qua
	 outreg, merge(table3)  	 nod keep( $m1  ) ctitle(" ", "")  ${option} addrows( "$model_4" \ "breakpoint", $breakpoint ) 
	  
	qui  `equa1' `y'  $m1   $regional $control $inc_control  $subview_control  if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 breakpoint_2010_qua
	 outreg, merge(table3) 	 nod keep( $m1  ) ctitle(" ", "")  ${option} addrows( "$model_5" \ "breakpoint", $breakpoint )  
		   
	*
	nois outreg  ,  replay(table3)  $option   title(Table 3)
	
	
******************************************************************************************************************************  	
****      Table 4 	
******************************************************************************************************************************  	

	local y = "Z_pca_score" 

	local l  :  variable label `y'
	dis "`l'"
	tempvar  samplee 
	g  `samplee' = ess_sample ==1 & sample_`y'==1 
	
	local equa1 = "areg"
	local equa2 = "absorb( id_country_yearess )"	

	outreg, clear(table4)	
	
	global m1  pct_2010  pct_2010_sq high_WELF_for2010  
	
	qui  `equa1' `y'    $m1      if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table4)	 nod keep( $m1   ) ctitle(" ", "`l'")  ${option} addrows( "$model_1" )
	  
	qui  `equa1' `y'    $m1  $regional      if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table4)		 nod keep( $m1   ) ctitle(" ", "")  ${option} addrows( "$model_2" )
	  
	qui  `equa1' `y'    $m1  $regional $control     if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table4)	 	 nod keep( $m1   ) ctitle(" ", "")  ${option} addrows( "$model_3" )
	  
	qui  `equa1' `y'  $m1  $regional $control $inc_control    if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table4)	  	 nod keep( $m1  ) ctitle(" ", "")  ${option} addrows( "$model_4" )
	  
	qui  `equa1' `y'  $m1   $regional $control $inc_control  $subview_control  if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table4)		 nod keep( $m1  ) ctitle(" ", "")  ${option} addrows( "$model_5")	
	
	nois outreg,  replay(table4)	 $option  title(Table 4)
	
******************************************************************************************************************************  	
****      Table 5 	
******************************************************************************************************************************  	

	local y = "Z_pca_score" 	
	
	local l  :  variable label `y'
	tempvar  samplee 
	g  `samplee' = ess_sample ==1 & sample_`y'==1 
	
	local equa1 = "areg"
	local equa2 = "absorb( id_country_yearess )"	

	outreg, clear(table5)		

	global m1  pct_2010  pct_2010_sq  edusimple3_for2010  
	global m2  pct_2010  pct_2010_sq  quant_hhincome1_for2010    quant_hhincome5_for2010  
	global m3  pct_2010  pct_2010_sq  edusimple3_for2010        quant_hhincome1_for2010   quant_hhincome5_for2010 
	global m4  pct_2010  pct_2010_sq   poor_ter_for2010 poor_noter_for2010   middle_ter_for2010  rich_ter_for2010  rich_noter_for2010  
	global control4                    poor_ter poor_noter middle_ter middle_noter rich_ter rich_noter 
	
	qui  `equa1' `y'    $m1  $regional $control $inc_control   i.edusimple     if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table5)	 nod keep( $m1   ) ctitle(" ", "`l'")  ${option} addrows( "$model_4" ) 
	  
	qui  `equa1' `y'    $m2  $regional $control $inc_control   i.edusimple   if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table5)	 nod keep( $m2   ) ctitle(" ", "")  ${option} addrows( "$model_4" ) 
	  
	qui  `equa1' `y'   $m3     $regional $control $inc_control   i.edusimple    if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table5)	 nod keep( $m3   ) ctitle(" ", "")  ${option} addrows( "$model_4") 
	  
	qui  `equa1' `y'  $m4  $control4  $regional $control $inc_control   i.edusimple   if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table5) 	 nod keep( $m4  ) ctitle(" ", "")  ${option} addrows( "$model_4") 
		
	nois	outreg,  replay(table5)	 $option 	 title(Table 5)

******************************************************************************************************************************  	
****      Table 6 	
******************************************************************************************************************************  	
		
	local y = "Z_pca_score" 	
	local l  :  variable label `y'
	tempvar  samplee 
	g  `samplee' = ess_sample ==1 & sample_`y'==1 
	local equa1 = "areg"
	local equa2 = "absorb( id_country_yearess )"	

	outreg, clear(table6)
	
	global m1  pct_2010  pct_2010_sq   leftist_for2010  leftist   
	global m2  pct_2010  pct_2010_sq   immi_bad_life1_for2010  immi_bad_life 
	global m3  pct_2010  pct_2010_sq   immi_NOrightsoc1_for2010   immi_NOrightsoc  
	
	qui  `equa1' `y'    $m1  $regional $control $inc_control   i.edusimple     if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table6)		 nod keep( $m1   ) ctitle(" ", "`l'")  ${option} addrows( "$model_4"  ) 
	  
	qui  `equa1' `y'    $m2  $regional $control $inc_control   i.edusimple   if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table6)	 	 nod keep( $m2   ) ctitle(" ", "")  ${option} addrows( "$model_4" ) 
	  
	qui  `equa1' `y'   $m3     $regional $control $inc_control   i.edusimple    if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table6)	 	 nod keep( $m3   ) ctitle(" ", "")  ${option} addrows( "$model_4" ) 
			
	nois outreg,  replay(table6)	 $option 	 title(Table 6)

******************************************************************************************************************************  	
****      Table 7 	
******************************************************************************************************************************  	
	

	local y = "Z_pca_score" 	
	local l  :  variable label `y'
	tempvar  samplee 
	g  `samplee' = ess_sample ==1 & sample_`y'==1 
	local equa1 = "areg"
	local equa2 = "absorb( id_country_yearess )"	

	outreg, clear(table7)	

	global m1  pct_2010  pct_2010_sq    old_pct2010  old 
	global m2  pct_2010  pct_2010_sq    tradi_pct2010 tradi
	global m3  pct_2010  pct_2010_sq    reli_pct2010 reli
	global m4  pct_2010  pct_2010_sq    altruist_pct2010   altruist
	global m5  pct_2010  pct_2010_sq    tolerant_pct2010 tolerant
	
	foreach j in  1 2 3 4 5 {
	global mx ${m`j'}
	qui  `equa1' `y'    $mx  $regional $control $inc_control      if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 breakpoint_2010_qua 
	 outreg, merge(table7)	 nod keep( $mx   ) ctitle(" ", "")  ${option} addrows( "$model_4" ) 
	  }
	  *
	nois outreg,  replay(table7)	 $option  title(Table 7)	
		
		

******************************************************************************************************************************  	
****      Table 8 	
******************************************************************************************************************************  	
	
	local y = "Z_pca_score" 	
	local l  :  variable label `y'
	tempvar  samplee 
	g  `samplee' = ess_sample ==1 & sample_`y'==1 
	local equa1 = "areg"
	local equa2 = "absorb( id_country_yearess )"	
	outreg, clear(table8)	
	
	global m1  pct_2010  pct_2010_sq    pct_EU15_2010  
	global m2  pct_2010  pct_2010_sq    pct_A10_2010 
	global m3  pct_2010  pct_2010_sq    pct_MiddleEast_2010 
	global m4  pct_2010  pct_2010_sq    pct_America_2010 
	global m5  pct_2010  pct_2010_sq    pct_Asia_2010 
	
	foreach j in  1 2 3 4 5 {
	global mx ${m`j'}
	qui  `equa1' `y'    $mx  $regional $control $inc_control      if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 breakpoint_2010_qua 
	 outreg, merge(table8)	 nod keep( $mx   ) ctitle(" ", "")  ${option} addrows( "$model_4" ) 
	  }
	  *
	nois	outreg,  replay(table8)	 $option	 title(Table 8)
		
		
		
******************************************************************************************************************************  	
****      Table 9 	
******************************************************************************************************************************  	
	

	local y = "Z_pca_score" 	
	local l  :  variable label `y'
	tempvar  samplee 
	g  `samplee' = ess_sample ==1 & sample_`y'==1 
	local equa1 = "areg"
	local equa2 = "absorb( id_country_yearess )"	
	outreg, clear(table9)	
		
		
	global ma1   pct_2010  pct_2010_sq  ln_rsc_mayda
	global ma2   pct_2010  pct_2010_sq   ln_rsc_topoccu
	
	foreach k in 1 2   {
		
		global m1 ${ma`k'}
		
	outreg, clear(table9_`k')	
		
	qui  `equa1' `y'    $m1   if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table9_`k')			 nod keep( $m1   ) ctitle(" ", "`l'")  ${option} addrows( "$model_1"  ) 
	  
	qui  `equa1' `y'    $m1  $regional      if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table9_`k')		 nod keep( $m1   ) ctitle(" ", "")  ${option} addrows( "$model_2") 
	  
	qui  `equa1' `y'    $m1  $regional $control     if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table9_`k')	 	 nod keep( $m1   ) ctitle(" ", "")  ${option} addrows( "$model_3") 
	  
	qui  `equa1' `y'  $m1 $regional $control $inc_control    if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table9_`k')	 	 nod keep( $m1  ) ctitle(" ", "")  ${option} addrows( "$model_4" ) 
	  
	qui  `equa1' `y'  $m1   $regional $control $inc_control  $subview_control  if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table9_`k')	 	 nod keep( $m1  ) ctitle(" ", "")  ${option} addrows( "$model_5" )  	

	 }
	 *
	nois  outreg,  replay(table9_1)	 $option  title(Table 9)
	nois outreg,  replay(table9_2)	 $option  title(Table 9)
		
		
***************************************************************************************************************
*** 	Table 10
****************************************************************************************************************
	
		
	local y = "Z_pca_score" 	
	local l  :  variable label `y'
	tempvar  samplee 
	g  `samplee' = ess_sample ==1 & sample_`y'==1 
	local equa1 = "areg"
	local equa2 = "absorb( id_country_yearess )"	
	outreg, clear(table10)
		
	global m1  pct_2010  pct_2010_sq    Z_dissi_index   pct_2010_Zdissi
		
	qui  `equa1' `y'    $m1   if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table10)			 nod keep( $m1   ) ctitle(" ", "`l'")  ${option} addrows( "$model_1" ) 
	  
	qui  `equa1' `y'    $m1  $regional      if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table10)		 nod keep( $m1   ) ctitle(" ", "")  ${option} addrows( "$model_2" ) 
	  
	qui  `equa1' `y'    $m1  $regional $control     if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table10)	 	 nod keep( $m1   ) ctitle(" ", "")  ${option} addrows( "$model_3" ) 
	  
	qui  `equa1' `y'  $m1 $regional $control $inc_control    if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table10)	 	 nod keep( $m1  ) ctitle(" ", "")  ${option} addrows( "$model_4" ) 
	  
	qui  `equa1' `y'  $m1   $regional $control $inc_control  $subview_control  if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(table10)		 	 nod keep( $m1  ) ctitle(" ", "")  ${option} addrows( "$model_5"  )  	


	nois outreg,  replay(table10)	 $option  title(Table 10)
	
		 
